package proj2501.geo_util;

public class VectorD3 {
	private double x;
	public double getX() { return x; }
	
	private double y;
	public double getY() { return y; }
	
	private double z;
	public double getZ() { return z; }

	public VectorD3(double x, double y, double z) {
		this.x = x;
		this.y = y;
		this.z = z;
	}
	
	@Override
	public String toString() {
		return "(" + x + ", " +  y + ", " + z + ")";
	}
	
	public double getLength() {
		return Math.sqrt(x * x + y * y + z * z);
	}
	
	public VectorD3 normalize() {
		double length = getLength();
		return new VectorD3(x / length, y / length, z / length);
	}
	
	public VectorD3 add(VectorD3 v) {
		return new VectorD3(x + v.x, y + v.y, z + v.z);
	}
	
	public VectorD3 sub(VectorD3 subtrahend) {
		return new VectorD3(x - subtrahend.x, y - subtrahend.y, z - subtrahend.z);
	}
	
	public VectorD3 mul(double scalar) {
		return new VectorD3(x * scalar, y * scalar, z * scalar);
	}
		
	public VectorD3 div(double scalar) {
		return new VectorD3(x / scalar, y / scalar, z / scalar);
	}
	
	public double dot(VectorD3 v) {
		return x * v.x + y * v.y + z * v.z;
	}
	
	public VectorD3 cross(VectorD3 v) {
		return new VectorD3(y * v.z - z * v.y, z * v.x - x * v.z, x * v.y - y * v.x);
	}
	
	public static VectorD3 getXVector() {
		return new VectorD3(1, 0, 0);
	}
	
	public static VectorD3 getYVector() {
		return new VectorD3(0, 1, 0);
	}
	
	public static VectorD3 getZVector() {
		return new VectorD3(0, 0, 1);
	}
}
